<div class="form-group" style="display:none;">
	<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">商品标签</label>
	<div class="col-md-6">
		<input type="text" name="goods[goodstab]" class="form-control" value="{$goods['goodstab']}" />
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 col-lg-1 control-label">服务时间</label>
	<div class="col-md-11">
		<table class="table table-hover">
			<thead>
			<tr>
				<th style='width:50px;'></th>
				<th>起始时间(如：9:00)</th>
				<th>截止时间（如:11:00）</th>
				<th>周数（如:1 表示星期一）</th>
				<th>库存（人数）</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody id="param-items">
				{loop $data $k $p}
				<tr>
					<td>
						<a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序"><i class="fa fa-arrows"></i></a>&nbsp;
						<a href="javascript:;" onclick="deleteParam(this)" style="margin-top:10px;" title="删除"><i class='fa fa-remove'></i></a>
					</td>
					<td>
						<input name="param_title[]" type="text" class="form-control param_title" value="{$p['start_time']}"/>
						<input name="param_id[]" type="hidden" class="form-control" value="{$p['id']}"/>
					</td>
					<td><input name="param_value[]" type="text" class="form-control param_value" value="{$p['end_time']}"/></td>
					<td><input name="param_week[]" type="text" class="form-control param_week" value="{$p['week']}" placeholder="数值：1" /></td>
					<td><input name="param_num[]" type="text" class="form-control " value="{$p['kucun']}" placeholder="人数 如：10" /></td>
					<td>
					{if $_W['uniacid'] == 4}<a onclick="get_code(this)" week="{$p['week']}" start="{$p['start_time']}"  data-toggle="modal" data-target="#myModal" style="margin-right: 10px;">生成项目二维码</a>{/if}      
					<a onclick="copy({$k},this)">复用</a></td>
				</tr> 
				{/loop}
			</tbody>
			<tbody>
				<tr>
					<td colspan="6">
						<a href="javascript:;" id='add-param' onclick="addParam()" style="margin-top:10px;"  title="添加属性">添加属性 <i class='fa fa-plus'></i></a>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						相同周数,会生成同一个二维码
					</h4>
				</div>
				<div class="modal-body" style="text-align: center;"> 
					<img  alt="项目二维码">
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
</div>

<script language="javascript">
    $(function(){
        $("#param-items").sortable({handle:'.fa-move'});
        $("#chkoption").click(function(){
            var obj =$(this);
            if(obj.get(0).checked){
                $("#tboption").show();
                $(".trp").hide();
            }
            else{
                $("#tboption").hide();
                $(".trp").show();
            }
        });
    })
	$(function(){
		$("#chkoption").click(function(){
			var obj =$(this);
			if(obj.get(0).checked){
				$("#tboption").show();
				$(".trp").hide();
			}
			else{
				$("#tboption").hide();
				$(".trp").show();
			}
		});
	})
	function addParam() {
		var html = '<td><input name="" type="text" class="form-control " value="" placeholder="数值：1" /></td><td><input name="" type="text" class="form-control " value="" placeholder="人数 如：10" /></td>';
		var url = "{php echo web_url('goods/param')}";
		$.ajax({
			"url": url ,
			success:function(data){
				$('#param-items').append(data);
			}
		});
		return;
	}
	function deleteParam(o) {
		$(o).parent().parent().remove();
	}
	<?php
		$js_data = json_encode($data);
	?>
	function copy(index,self){
		// console.log({$js_data}[index]);  
		var index_last = $('#param-items').find('tr').length;  
		html = '<tr>'+
					'<td>'+ 
						'<a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序"><i class="fa fa-arrows"></i></a>&nbsp;'+
						'<a href="javascript:;" onclick="deleteParam(this)" style="margin-top:10px;" title="删除"><i class="fa fa-remove"></i></a>'+
					'</td>'+
					'<td>'+
						'<input name="param_title[]" type="text" class="form-control param_title" value='+{$js_data}[index].start_time+'>'+
						'<input name="param_id[]" type="hidden" class="form-control" value=""/>'+
					'</td>'+
					'<td><input name="param_value[]" type="text" class="form-control param_value" value='+{$js_data}[index].end_time+'></td>'+
					'<td><input name="param_week[]" type="text" class="form-control param_week" value='+{$js_data}[index].week+' placeholder="数值：1" /></td>'+
					'<td><input name="param_num[]" type="text" class="form-control " value='+{$js_data}[index].kucun+' placeholder="人数 如：10" /></td>'+
					'<td><a onclick="get_code(this)" week='+{$js_data}[index].week+' start='+{$js_data}[index].start_time+' data-toggle="modal" data-target="#myModal">生成项目二维码</a></td>'+     
				'</tr>'
		 $('#param-items').append(html);  
	}
	function get_code(self) {
	    var html = "相同周数,会生成同一个二维码,确认生成?";
	    var week = $(self).parent().parent().find('.param_week').val();
		var start = $(self).parent().parent().find('.param_title').val();
		var goodsid = window.GetQueryString('id'); 
		var start_time = "{$start_time}";
		var end_time = "{$end_time}";
		console.log($(self));
		window.post_code(start_time,end_time,week,start,goodsid) 
 	}

	//获取url参数
    function GetQueryString(name){
	    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	    var r = window.location.search.substr(1).match(reg);
	    if(r!=null)return  unescape(r[2]); return null;
	}
	function post_code (start_time,end_time,week,start,goodsid) {
		$.post("{php echo web_url('goods/goods/item_qrcode')}",
	       {start_time:start_time,end_time:end_time,week:week,start:start,goodsid:goodsid}, 
	       function (res) {
	      	res = JSON.parse(res);
	      	if(res.status == 1) {
	      		$('.modal-body').find('img').attr('src',res.url);
	      	}else{
	      		$('.modal-body').html('获取项目二维码失败!!')  
	      	}
	      	
	      }); 
	}

</script>


